<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:index.php");
}
else
{
	$incomingRegister = 0;
	if(isset($_POST['submit']))
  {
  	$loopCount = 0; 
    while($loopCount < count($_POST['menuId']))
  	{   
  	  $userId = ($_POST['userId'] != '') ? $_POST['userId'] : 0;
  	  $menuId  = ($_POST['menuId'][$loopCount] != '') ? $_POST['menuId'][$loopCount] : 0;
  		$insertBillMaster  = "INSERT INTO usermenu (userId, menuId)
  		                     VALUES (".$userId.",".$menuId.")";
      $insertBillMasterRes = mysql_query($insertBillMaster);
  	  if(!$insertBillMasterRes)
  	  {
  	  	die("Insert Query Not Inserted :".mysql_error());
  	  }
  	  else
  	  {
  	  	header("Location:bill.php");
  	  }
  	  $loopCount++;
    }
  }
	
  $incomingRegister = array();
  $i =0;
  $selectincomingRegister = "SELECT menuId,menuName
                               FROM menu
                           ORDER BY menuName";
  $selectincomingRegisterRes = mysql_query($selectincomingRegister);
  while($incomingRow = mysql_fetch_array($selectincomingRegisterRes))
  {
  	$incomingRegister[$i]['menuId'] = $incomingRow['menuId'];
  	$incomingRegister[$i]['menuName'] = $incomingRow['menuName'];
  	$i++;
  }
	
  $partyArray = array();
  $k = 0;
  $select = "SELECT userId,userName
               FROM user
              ORDER BY userName";
  $selectResult = mysql_query($select);
  while($row = mysql_fetch_array($selectResult))
  {
    $partyArray['userId'][$k]   = $row['userId'];
    $partyArray['userName'][$k] = $row['userName'];
    $k++;
  }
  
  include("./bottom.php");
  $smarty->assign("msg",'<font size="6">No Record Found</font>');
	$smarty->assign("partyArray",$partyArray);
	$smarty->assign("incomingRegister",$incomingRegister);
  $smarty->display('bill.tpl');
}
?>